package com.study.lu.thread.producercustomer;

import com.study.lu.thread.producercustomer.newjdk.FoodFactoryByLock;
import com.study.lu.thread.producercustomer.oldjdk.FoodFactory;

import java.util.List;

/**
 * <b>System：</b>incommonusefactory<br/>
 * <b>Title：</b>Producer.java<br/>
 * <b>Description：</b> 对功能点的描述<br/>
 * <b>@author： </b>raoluping<br/>
 * <b>@date：</b>2017/12/20 17:25<br/>
 * <b>@version：</b> 1.0.0.0 <br/>
 * <b>Copyright (c) 2017 ASPire Tech.</b>
 */
public class ProducerThread implements Runnable {
    private String name;

    private FoodFactory foodFactory;

    private FoodFactoryByLock foodFactoryByLock;

    public ProducerThread(String name, FoodFactory foodFactory) {
        this.name = name;
        this.foodFactory = foodFactory;
    }

    public ProducerThread(String name, FoodFactoryByLock foodFactoryByLock) {
        this.name = name;
        this.foodFactoryByLock = foodFactoryByLock;
    }

    @Override
    public void run() {
        try {
            while (true) {
                if (null != foodFactory) {
                    foodFactory.producerFood();
                } else {
                    foodFactoryByLock.producerFood();
                }
                // Thread.sleep(500);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
